package com.shadow.study.jpa.service;

import com.shadow.study.jpa.entity.JPARoleEntity;
import com.shadow.study.jpa.repository.JPARoleRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class JPARoleService {

    @Resource
    private JPARoleRepository roleRepository;

    public JPARoleEntity findByName(final String name) {
        return roleRepository.findByName(name);
    }

    public List<JPARoleEntity> findByCodeLike(final String name) {
        return roleRepository.findByCodeLike(name);
    }

    public Page<JPARoleEntity> findAll(Pageable pageable) {
        return roleRepository.findAll(pageable);
    }

    public JPARoleEntity save(final JPARoleEntity roleEntity) {
        return roleRepository.save(roleEntity);
    }

    public void delete(final String id) {
        roleRepository.deleteById(id);
    }
}
